package trafficgeneratorcr.gui;

import java.awt.BorderLayout;
import java.awt.geom.Arc2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.renderer.xy.XYSplineRenderer;
import org.jfree.data.xy.DefaultXYDataset;

public class PlotterPanel extends JPanel {

    private DefaultXYDataset dataSet;
    private XYPlot plot;

    public PlotterPanel() {
        super(new BorderLayout());

        dataSet  = new DefaultXYDataset();
        XYSplineRenderer renderer = new XYSplineRenderer(10);
        //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

        //renderer.setBaseShapesVisible(true);
        //renderer.setBaseLinesVisible(false);
        //renderer.setBaseShape(new Rectangle2D.Double());
        DateAxis domainAxis = new DateAxis();
        ValueAxis rangeAxis = new NumberAxis("Probability [%]");

        //rangeAxis.setVisible(false);
        //rangeAxis.setAutoRange(false);
        //rangeAxis.setRange(0, 100);

        //domainAxis.setTickLabelsVisible(false);

        plot = new XYPlot(dataSet, domainAxis, rangeAxis, renderer);
        JFreeChart chart = new JFreeChart(plot);
        chart.removeLegend();
        ChartPanel chartPanel = new ChartPanel(chart);

        this.add(chartPanel, BorderLayout.CENTER);
    }

    public void setPlotData(double[] values) {
        double[] xValues = new double[values.length];
        for (int i = 0; i < xValues.length; i++)
            xValues[i] = i;

        this.dataSet.addSeries("default", new double[][] {xValues, values});
    }

}
